package com.heima.wemedia.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.wemedia.dtos.WmchannelDto;
import com.heima.model.common.wemedia.pojos.WmChannel;
import com.heima.wemedia.mapper.WmChannelMapper;
import com.heima.wemedia.service.WmChannelService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
@Slf4j
public class WmChannelServiceImpl extends ServiceImpl<WmChannelMapper, WmChannel> implements WmChannelService {


    /**
     * 查询所有频道
     *
     * @return
     */
    @Override
    public List<WmChannel> findAll() {
        List<WmChannel> list = this.list();
        return list;
    }

    /**
     * 频道名称模糊分页查询
     * @return
     */
    @Override
    public Page listAndLike(WmchannelDto wmchannelDto) {

        Page page = new Page<>(wmchannelDto.getPage(), wmchannelDto.getSize());

        LambdaQueryWrapper<WmChannel> lqw = new LambdaQueryWrapper<>();
        lqw.like(StringUtils.isNotEmpty(wmchannelDto.getName()),
                WmChannel::getName, wmchannelDto.getName());
        this.page(page, lqw);

        return page;
    }
}